package me.itsoo.artemis.framework.core.enumer;

/**
 * VirtualEnum
 *
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/1
 */
@SuppressWarnings("squid:S1452")
public interface VirtualEnum<T extends VirtualEnum<?>> {

    String ENUM_ALL = "enumAll";

    String ENUM_NAME = ".enumName";

    /**
     * 枚举名称
     *
     * @return String
     */
    String name();

    /**
     * 枚举类型
     *
     * @return Class
     */
    Class<? extends Enum<?>> getDeclaringClass();

    /**
     * 枚举取值
     *
     * @return Integer
     */
    default Integer getCode() {
        return (Integer) Helper.create(this.getDeclaringClass()).get(this.name() + ENUM_NAME);
    }

    /**
     * 枚举比较
     *
     * @param t T
     * @return boolean
     */
    default boolean isEquals(T t) {
        return (this == t) || (t != null && this.isEquals(t.getCode()));
    }

    /**
     * 枚举比较
     *
     * @param code Integer
     * @return boolean
     */
    default boolean isEquals(Integer code) {
        return this.getCode().equals(code);
    }
}
